package per.liu.ibatis;

import org.joda.time.DateTime;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;

import java.sql.Types;
import java.util.List;
import java.util.Properties;

/**
 * Created by Administrator on 2015/2/11.
 */
public class DateTimeTypeResolver extends JavaTypeResolverDefaultImpl {

	@Override public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn introspectedColumn) {
		System.out.println("-----------"+introspectedColumn.getJdbcType());
		FullyQualifiedJavaType fullyQualifiedJavaType = super.calculateJavaType(introspectedColumn);
		System.out.println("============"+fullyQualifiedJavaType.getFullyQualifiedName());
		if (introspectedColumn.getJdbcType()== Types.TIMESTAMP) {
			introspectedColumn.setTypeHandler(DateTimeTypeHandler.class.getName());
			return new FullyQualifiedJavaType(DateTime.class.getName());
		}
		return super.calculateJavaType(introspectedColumn);
	}

	@Override public String calculateJdbcTypeName(IntrospectedColumn introspectedColumn) {
		return super.calculateJdbcTypeName(introspectedColumn);
	}
}
